﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using _4m.Utils;

namespace _4m.forms
{
    public partial class DirPickerForm : Form
    {
        private FolderBrowserDialog folderBrowserDialog;

        public DirPickerForm()
        {
            if (this.folderBrowserDialog == null)
            {
                this.folderBrowserDialog = new FolderBrowserDialog();
            }
            InitializeComponent();
        }

        public void ShowForm()
        {
            folderBrowserDialog.ShowDialog();

            string selectedPath = folderBrowserDialog.SelectedPath;
            this.txtBoxOnWeek.Text = string.Format("{0}\\按周发病", selectedPath);
            this.txtBoxClassAB.Text = string.Format("{0}\\甲乙类传染病分析", selectedPath);
            this.txtBoxHFMD.Text = string.Format("{0}\\手足口病", selectedPath);
        }

        private void BtnSubmitClick(object sender, EventArgs e)
        {
            Debug.WriteLineIf(Constants.Debug, string.Format("选择的文件夹：{0}", this.folderBrowserDialog.SelectedPath));
            
            string onWeekDirString = this.txtBoxOnWeek.Text;
            if (!Directory.Exists(onWeekDirString))
            {
                MessageBox.Show(string.Format("不存在该目录：{0}", onWeekDirString), "提示信息", MessageBoxButtons.OK);
                return;
            }
            string classAbDirString = this.txtBoxClassAB.Text;
            if (!Directory.Exists(classAbDirString))
            {
                MessageBox.Show(string.Format("不存在该目录：{0}", classAbDirString), "提示信息", MessageBoxButtons.OK);
                return;
            }
            string hfmdDirString = this.txtBoxHFMD.Text;
            if (!Directory.Exists(hfmdDirString))
            {
                MessageBox.Show(string.Format("不存在该目录：{0}", hfmdDirString), "提示信息", MessageBoxButtons.OK);
                return;
            }

            FileInfo[] onWeekFiles = this.GetFiles(onWeekDirString);
            FileInfo[] classAbFiles = this.GetFiles(classAbDirString);
            FileInfo[] hfmdFiles = this.GetFiles(hfmdDirString);

            this.Close();
        }

        private FileInfo[] GetFiles(string dirString)
        {
            var directoryInfo = new DirectoryInfo(dirString);
            var files = directoryInfo.GetFiles();
            Debug.WriteLineIf(Constants.Debug, string.Format("目录{0}的文件数：{1}", dirString, files.Count()));
            return files;
        }
    }
}
